<?php
/**
 * @page dynamic_page_link_module Dynamic Page Link Module
 * 
 * This module can be used to generate links of @ref dynamic_pages. The links will be generated based on
 * the values of field selected at the time of creation of dynamic page.
 * 
 * @image html dynamic_page_module.jpg
 * 
 * Visible link keys allows you to show only specific links, support you have a field 'city' with 50
 * different values, but you want to show only first 5 cities you entered in the options. So you can
 * define link keys as: 1,2,3,4,5
 *
 */
	class DynamicPageModule extends GigaModule
	{
		var $name = 'Dynamic Page Links';
		var $configuration = array();
		function __construct()
		{
			$this->configuration = array(
			'page_field' => array("type"=>"select",'label'=>__("Page Name"),'validate'=>VALID_NOT_EMPTY,'empty'=>__("-Select-")),
			'limit' => array("type"=>"text",'default'=>15,'after'=>__("Number of places visible.")),
			'visible_links_keys'=>array('type'=>"text","tooltip"=>__("Should be comma seperated list.")),
			'show_active' => array("label"=>__("Show present active page."),"type"=>"checkbox"),
			'sort_order' => array("type"=>"select","options"=>array("asc"=>__("Asc"),"desc"=>__("Desc")),'empty'=>__("-None-"))
			); 
			$pagesInfo = cri("DynamicPage")->getPageFieldsInfo();
			$options = array();
			foreach($pagesInfo as $pageInfo)
			{
				$options[$pageInfo['DynamicPage']['field']] = $pageInfo['DynamicPage']['name'];
			}
			$this->configuration['page_field']['options'] = $options;
		}
		
		function render($params)
		{
			extract($params);
			$field= $page_field;
			$pageInfo = cri('DynamicPage')->getPageInfo($field);
			$visibleLinksKeys = explode(",",$visible_links_keys);
			$visibleLinksKeys = Set::filter($visibleLinksKeys);
			return ClassRegistry::getObject("View")->element('dynamic_page_links',array(
				'visibleLinksKeys'=>$visibleLinksKeys,'limit'=>$limit,'pageInfo'=> $pageInfo,'order'=>$sort_order,'showActive'=> $show_active));
		}
	}
?>